<template>
  <div>
    <div class="remove-all clearfix">
      <el-button
        size="mini"
        class="float-right"
        type="danger"
        @click="removeAllBtnClick()">删除所有</el-button>
    </div>

    <el-table
      :data="files">
      <el-table-column
        label="文件名">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="detail"
        label="图片"
        width="70">
        <template slot-scope="scope">
          <el-popover
            trigger="hover"
            placement="top">
            <img
              :src="scope.row.filePath"
              alt=""
              style="max-width: 200px;">
            <div
              slot="reference"
              class="name-wrapper">
              <el-tag size="medium">图片</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="70">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            @click="deleteBtnClick(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import ECSFileModel from '@/models/ecs/ECSFileModel'
export default {
  name: 'AdminServerEcs',
  data() {
    return {
      /**
       * 文件列表
       */
      files: []
    }
  },
  mounted() {
    this.getAllFile()
  },
  methods: {
    /**
     * 获取所有文件
     */
    getAllFile() {
      ECSFileModel.loadAllModels().then((dataArr) => {
        console.log('dataArr = ', dataArr)
        this.files = dataArr
      }).catch(() => {})
    },
    /**
     * 删除按钮点击
     * @param index
     * @param item
     */
    deleteBtnClick(item) {
      item.remove('name').then(() => {
        this.getAllFile()
      }).catch(() => {})
    },
    /**
     * 删除所有数据
     */
    removeAllBtnClick() {
      this.$w_remove_pop(() => {
        return ECSFileModel.removeAll()
      }, '所有数据').then(() => {
        this.getAllFile()
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>

  .remove-all {
    padding-bottom: 20px;
  }

</style>
